package com.cloudkinto.bo.order.outbound;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

@Data
public class NormalOrderOutboundApiQueryBo {
    public Integer current = 1;
    public Integer pageSize = 20;
//    private Long companyId;
    @ApiModelProperty(value = "时间类型 1创建 2波次 3拣货 4复核 5称重 6出库 7 提交时间 8取消时间")
    private Integer timeType = 1;

    @ApiModelProperty("开始时间")
    private String startDate;

    @ApiModelProperty("结束时间")
    private String endDate;

    @ApiModelProperty("目前只支持 1(待处理) 7(已取消), 传其他值 默认1")
    private Integer status;

    @ApiModelProperty(value = "出库单号")
    private List<String> outboundNoList;

    public String getStartDate() {
        if (StringUtils.isBlank(startDate)) {
            return DateUtil.format(DateUtil.offsetDay(new Date(), -30), "yyyy-MM-dd");
        }
//        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//        LocalDateTime dateTime = LocalDate.parse(startDate, format).atTime(0, 0, 0);
//        return  DateUtil.format(Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant()),  "yyyy-MM-dd");
        return startDate;
    }

    public String getEndDate() {
        if (StringUtils.isBlank(endDate)) {
            return DateUtil.format(DateUtil.offsetDay(new Date(), 1), "yyyy-MM-dd");
        }
//        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//        LocalDateTime dateTime = LocalDate.parse(endDate, format).atTime(23, 59, 59);
//        return  DateUtil.format(Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant()),  "yyyy-MM-dd");
        return endDate;
    }

    public Integer getPageSize() {
        if (pageSize > 200) {
            return 200;
        }
        if (pageSize < 1) {
            return 10;
        }
        return pageSize;
    }
}
